package com.zen.lon.open.remote.context;

import com.zen.lon.open.proxy.ProxyAgentFactory;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 代理bean工厂实现的上下文, 默认获取都是单例的
 *
 * @author ZonLen since on 2021/7/12 下午1:19
 */
public class FactoryBeanContext {

  /**
   * 代理类工厂缓存
   */
  private static final Map<Class<?>, ProxyAgentFactory> PROXY_FACTORIES_CACHE = new ConcurrentHashMap<>();

  /**
   * 创建代理
   */
  public <P> P newProxy(Class<P> proxyClass) {
    return PROXY_FACTORIES_CACHE.computeIfAbsent(proxyClass, p -> new ProxyAgentFactory())
        .newProxy(proxyClass);
  }


}
